package gentle.controller;

import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.BaseController;
import gentle.entity.CustomerInfo;
import gentle.entity.SearchCustomerInfo;
import gentle.factory.PageFactory;
import gentle.service.ICardDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;

/**
 * 储值明细
 *
 * @author py
 * @Date 2018年4月19日23:15:54
 */
@RestController
@RequestMapping("cardDetail")
public class CardDetailController extends BaseController {

    @Autowired
    ICardDetailService cardDetailService;

    /**
     * 储值明细管理列表1
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object testrInfoList(SearchCustomerInfo info, HttpServletRequest request) {
        if(info.getAbbreviation()==null || info.getAbbreviation() =="" || info.getAbbreviation() == "null"){
            return null;
        }else{
            Page<CustomerInfo> page = new PageFactory<CustomerInfo>().defaultPage();
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<CustomerInfo> list = cardDetailService.selectPageListByQueryGetMap(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = cardDetailService.selectPageListByQueryGetMap(page, info);
                }
                page.setTotal(cardDetailService.getQueryPagesCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }

    /**
     * 储值明细2管理列表
     */
    @RequestMapping("/detailList")
    @ResponseBody
    public Object detailListInfoList(SearchCustomerInfo info) {
        if(info.getAbbreviation()==null || info.getAbbreviation()=="" || info.getAbbreviation()=="null"){
            return null;
        }else{
            Page<CustomerInfo> page = new PageFactory<CustomerInfo>().defaultPage();
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<CustomerInfo> list = cardDetailService.selectPageDetailListByQueryGetMap(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = cardDetailService.selectPageDetailListByQueryGetMap(page, info);
                }
                page.setTotal(cardDetailService.getQueryPagesDetailCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }



    /**
     * 储值明细统计查询
     */
    @RequestMapping("/sumCardDetail")
    @ResponseBody
    public HashMap sumCardDetail(@RequestParam(required = false) String reach, @RequestParam(required = false) String customerStatus,@RequestParam(required = false) String modeName,@RequestParam(required = false) String checkoutMethod,
                                 @RequestParam(required = false) String fieldTc, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime,
                                 @RequestParam(required = false) String outpatientName, @RequestParam(required = false) String abbreviation) {
        return cardDetailService.sumCardDetail(reach, customerStatus, fieldTc, modeName, checkoutMethod, startTime, endTime,outpatientName,abbreviation);
    }


    @RequestMapping(value = "/cardDetailExport")
    public void cardDetailExport(@Valid SearchCustomerInfo searchInfo, HttpServletResponse response) {
        cardDetailService.cardDetailExport(searchInfo,response);

    }

    @RequestMapping(value = "/cardDetailExportTwo")
    public void cardDetailExportTwo(@Valid SearchCustomerInfo searchInfo, HttpServletResponse response) {
        cardDetailService.cardDetailExportTwo(searchInfo,response);
    }

}
